//package com.hshx.config;
//
//import io.swagger.annotations.ApiOperation;
//import org.springframework.beans.BeansException;
//import org.springframework.beans.factory.config.BeanPostProcessor;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.util.ReflectionUtils;
//import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping;
//import springfox.documentation.builders.ApiInfoBuilder;
//import springfox.documentation.builders.PathSelectors;
//import springfox.documentation.builders.RequestHandlerSelectors;
//import springfox.documentation.service.ApiInfo;
//import springfox.documentation.service.Contact;
//import springfox.documentation.spi.DocumentationType;
//import springfox.documentation.spring.web.plugins.Docket;
//import springfox.documentation.spring.web.plugins.WebFluxRequestHandlerProvider;
//import springfox.documentation.spring.web.plugins.WebMvcRequestHandlerProvider;
//
//import java.lang.reflect.Field;
//import java.util.List;
//import java.util.stream.Collectors;
//
//@Configuration
//public class Swagger3Config {
//    @Bean
//    public Docket createRestApi() {
//        //添加header参数
//        /*List<Parameter> list = new ArrayList<Parameter>();
//        ParameterBuilder token = new ParameterBuilder();
//        token.name("token").description("令牌").modelRef(new ModelRef("String")).parameterType("header").required(false);
//        list.add(token.build());*/
//
//        return new Docket(DocumentationType.OAS_30)	//3.0版本
//                .apiInfo(apiInfo())            //文档信息
//                .select().apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
////.apis(RequestHandlerSelectors.basePackage("com"))	//配置需要扫描的controller位置
//                .paths(PathSelectors.any())     //配置路径
//                .build();	//.globalOperationParameters(list);
//    }
//    @Bean
//    public static BeanPostProcessor springfoxHandlerProviderBeanPostProcessor() {
//        return new BeanPostProcessor() {
//            //@Override
//            public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
//                if (bean instanceof WebMvcRequestHandlerProvider || bean instanceof WebFluxRequestHandlerProvider) {
//                    customizeSpringfoxHandlerMappings(getHandlerMappings(bean));
//                }
//                return bean;
//            }
//            private <T extends RequestMappingInfoHandlerMapping> void customizeSpringfoxHandlerMappings(List<T> mappings) {
//                List<T> copy = mappings.stream()
//                        .filter(mapping -> mapping.getPatternParser() == null)
//                        .collect(Collectors.toList());
//                mappings.clear();
//                mappings.addAll(copy);
//            }
//            @SuppressWarnings("unchecked")
//            private List<RequestMappingInfoHandlerMapping> getHandlerMappings(Object bean) {
//                try {
//                    Field field = ReflectionUtils.findField(bean.getClass(), "handlerMappings");
//                    field.setAccessible(true);
//                    return (List<RequestMappingInfoHandlerMapping>) field.get(bean);
//                } catch (IllegalArgumentException | IllegalAccessException e) {
//                    throw new IllegalStateException(e);
//                }
//            }
//        };
//    }
//
//    private ApiInfo apiInfo() {
//        return new ApiInfoBuilder()
//                .title("Swagger3接口文档")              //标题
//                .description("项目前后端接口文档，更多请咨询服务开发者。")
//                .contact(new Contact("豪石宏鑫公司您值得信赖", "http://www.baidu.com", "2678300101@qq.com"))                     //联系人信息
//                .version("1.0")
//                .build();
//    }
//}
